/**
  ******************************************************************************
  * @file    gt32f030_basetim.c
  * @author  GT Application Team
  * @version V1.0.0
  * @date    03-January-2025
  *       
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 Giantec Semicondutor Inc</center></h2>
  *
  *             http://www.giantec-semi.com/
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GT32F030_BASETIM_H
#define __GT32F030_BASETIM_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "gt32f030.h"

/** @addtogroup GT32F030_StdPeriph_Driver
  * @{
  */

/** @addtogroup BTIM
  * @{
  */ 

/* Exported macro ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

/** @defgroup BTIM_Exported_Constants
  * @{
  */ 
#define IS_BTIM_ALL_PERIPH(PERIPH) (((PERIPH) == TIM10) || \
                                    ((PERIPH) == TIM11))

/** @defgroup BTIM_ClkPrescale_define 
  * @{
  */ 
typedef enum
{ 
  BTIM_ClkPrescale_div1       = 0x00,
  BTIM_ClkPrescale_div2       = 0x01,
  BTIM_ClkPrescale_div4       = 0x02,
  BTIM_ClkPrescale_div8       = 0x03,
  BTIM_ClkPrescale_div16      = 0x04,
  BTIM_ClkPrescale_div32      = 0x05,
  BTIM_ClkPrescale_div64      = 0x06,
  BTIM_ClkPrescale_div128     = 0x07
}BTIMClkPrescale_TypeDef;
#define IS_BTIM_CLKPRSC(CLKPRSC) (((CLKPRSC) == BTIM_ClkPrescale_div1)     || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div2)     || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div4)     || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div8)     || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div16)    || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div32)    || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div64)    || \
                                  ((CLKPRSC) == BTIM_ClkPrescale_div128))
/**
  * @}
  */ 


/** @defgroup BTIM_function_configuration_define 
  * @{
  */
typedef enum
{ 
  BTIM_GatePole_Low       = 0x00,
  BTIM_GatePole_High      = 0x01
}BTIMGatePole_TypeDef;
#define IS_BTIM_GATEPOLE(POLE) (((POLE) == BTIM_GatePole_Low)     || \
                                ((POLE) == BTIM_GatePole_High))

typedef enum
{ 
  BTIM_FunctionMode_Timer       = 0x00,
  BTIM_FunctionMode_Counter     = 0x01
}BTIMFunctionMode_TypeDef;
#define IS_BTIM_FUNCTIONMODE(FUNMODE) (((FUNMODE) == BTIM_FunctionMode_Timer)     || \
                                       ((FUNMODE) == BTIM_FunctionMode_Counter))

typedef enum
{ 
  BTIM_LoadMode_FreeRun       = 0x00,
  BTIM_LoadMode_AtuoReload    = 0x01
}BTIMLoadMode_TypeDef;
#define IS_BTIM_LOADMODE(LOADMODE) (((LOADMODE) == BTIM_LoadMode_FreeRun)     || \
                                    ((LOADMODE) == BTIM_LoadMode_AtuoReload))

typedef enum
{ 
  BTIM_CountSize_16Bit    = 0x00,
  BTIM_CountSize_32Bit    = 0x01
}BTIMCountSize_TypeDef;
#define IS_BTIM_COUNTSIZE(SIZE)    (((SIZE) == BTIM_CountSize_16Bit)     || \
                                    ((SIZE) == BTIM_CountSize_32Bit))

typedef enum
{ 
  BTIM_RunMode_Repeate    = 0x00,
  BTIM_RunMode_Oneshot    = 0x01
}BTIMRunMode_TypeDef;
#define IS_BTIM_RUNMODE(RUNMODE)   (((RUNMODE) == BTIM_RunMode_Repeate)  || \
                                    ((RUNMODE) == BTIM_RunMode_Oneshot))
/**
  * @}
  */ 

/**
  * @}
  */


/* Exported types ------------------------------------------------------------*/
/** 
  * @brief   BTIM Init structure definition  
  */ 
typedef struct 
{
	BTIMGatePole_TypeDef     BTIM_GatePole;
	BTIMFunctionMode_TypeDef BTIM_FunctionMode;
	BTIMLoadMode_TypeDef     BTIM_LoadMode;
	BTIMCountSize_TypeDef    BTIM_CountSize;
	BTIMRunMode_TypeDef      BTIM_RunMode;
	BTIMClkPrescale_TypeDef  BTIM_ClkPrescale;

	FunctionalState     BTIM_GateCmd;
	FunctionalState     BTIM_ToggleCmd;	
  unsigned int            BTIM_LoadVal; 
  unsigned int            BTIM_BGLoadVal; 	                 
}BTIM_InitTypeDef;



/* Exported functions --------------------------------------------------------*/
void BTIM_DeInit(void);
void BTIM_Init(BTIM_TypeDef* BTIMx,BTIM_InitTypeDef* BTIM_InitStruct);
void BTIM_StructInit(BTIM_InitTypeDef* BTIM_InitStruct);

void BTIM_Cmd(BTIM_TypeDef* BTIMx,FunctionalState NewState);
void BTIM_SetLoadVal(BTIM_TypeDef* BTIMx,unsigned int LoadVal);
void BTIM_SetBGLoadVal(BTIM_TypeDef* BTIMx,unsigned int BGLoadVal);
unsigned int BTIM_GetCountVal(BTIM_TypeDef* BTIMx);

void BTIM_ITConfig(BTIM_TypeDef* BTIMx,FunctionalState NewState);
ITStatus BTIM_GetIT(BTIM_TypeDef* BTIMx);
ITStatus BTIM_GetRawIT(BTIM_TypeDef* BTIMx);
void BTIM_ClearIT(BTIM_TypeDef* BTIMx);

#ifdef __cplusplus
}
#endif

#endif /* __GT32F030_BTIM_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/************************ (C) COPYRIGHT Giantec Semicondutor Inc *****END OF FILE****/
